import cv2

# 打开默认的摄像头（通常为0，如果你有多个摄像头，可能需要更改此数字）
cap = cv2.VideoCapture('rtsp://admin:hxt@2025@192.168.31.199:554/cam/realmonitor?channel=1&subtype=0')

# 检查摄像头是否成功打开
if not cap.isOpened():
    print("无法打开摄像头")
else:
    # 获取并打印原始分辨率
    # cap.set(cv2.CAP_PROP_FRAME_WIDTH, 3840)
    # cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 2160)
    fps = cap.get(cv2.CAP_PROP_FPS)
    print(fps)

    # cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc(*'MJPG'))
    # cap.set(cv2.CAP_PROP_FPS, 60)
    # fps = cap.get(cv2.CAP_PROP_FPS)
    # print(fps)
    
i = 1
while True:
    ret, frame = cap.read()
    if ret:
        cv2.imwrite('usb_img/' +str(i)+'.jpg', frame)
    else:
        print("无法从摄像头读取帧")
        break
    i+=1



        